// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import 'styles/reset.css'
import 'styles/border.css'
import store from './store'

import MessageBox from 'common/MessageBox/index';
Vue.use(MessageBox);

router.beforeEach((to, from, next) => {
	// console.log('跳转前' + JSON.stringify(to));
	if (to.meta.title) {
		document.title = to.meta.title
	}
	const type = to.meta.type
	if (type === 'login') {
		if(localStorage.getItem('userInfo')){
			next();
		} else {
			next('/login');
		}
	} else {
		next();
	}
});
router.afterEach((to, from, next) => {
  window.scrollTo(0, 0);
});

// 移动端适配
import '../static/js/flexible.js'

/* 300毫秒点击延迟问题的解决方案（尤其是移动端）优化用户体验 */
import fastClick from 'fastclick'
fastClick.attach(document.body)

// 全局引入Toast
import 'common/Toast/toast.css';
import Toast from 'common/Toast/index';
Vue.use(Toast);

import http from 'api'
Vue.prototype.$http = http

import Mheader from 'common/m-header'
Vue.component('m-header', Mheader);

Vue.config.productionTip = false
/* eslint-disable no-new */
new Vue({
	el: '#app',
	router,
	store,
	components: {
		App
	},
	template: '<App/>'
})
